package com.baseDemo.web.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baseDemo.web.entity.QuartzEntity;
import com.baseDemo.web.service.quartz.QuartzService;
import com.share.hibernate.baseDaoSupport.PageUtil;

@Controller
@RequestMapping(value="/quartzCron" ,produces="application/json;charset=UTF-8")
public class QuartzCronController {
	
	@Resource QuartzService quartzService;
	
	@RequestMapping(value="/getAllByPage",produces="application/json;charset=UTF-8") 
	public @ResponseBody PageUtil getAllByPage(@RequestParam("page") Integer page,@RequestParam("limit") Integer limit,@RequestParam("start") Integer start) {
		return quartzService.getListForPageToJson(start, limit);
	}
	/**
	 * 添加新纪录任务
	 * @param quartzEntity
	 * @return
	 */
	@RequestMapping(value="/addQuartzCron") 
	@ResponseBody
	public String addQuartzCron(@RequestBody QuartzEntity quartzEntity){
		return "{'id':'"+quartzService.save(quartzEntity)+"'}";
	}
	/**
	 * 修改
	 * @param quartzEntity
	 * @return
	 */
	@RequestMapping(value="/updateQuartzCron") 
	@ResponseBody
	public String updateQuartzCron(@RequestBody QuartzEntity quartzEntity){
		return quartzService.update(quartzEntity);
	}
	/**
	 * 删除
	 * @param quartzEntity
	 * @return
	 */
	@RequestMapping(value="/destroyQuartzCron") 
	@ResponseBody
	public String destroyQuartzCron(@RequestBody QuartzEntity quartzEntity){
		return quartzService.delete(quartzEntity);
	}
	/**
	 * 启动任务
	 * @param quartzEntity
	 * @return
	 */
	@RequestMapping(value="/startQuartzCron") 
	@ResponseBody
	public String startQuartzCron(@RequestBody QuartzEntity quartzEntity){
		return quartzService.startQuartzCron(quartzEntity);
	}
	/**
	 * 暂停任务
	 * @param quartzEntity
	 * @return
	 */
	@RequestMapping(value="/pauseQuartzCron") 
	@ResponseBody
	public String pauseQuartzCron(@RequestBody QuartzEntity quartzEntity){
		return quartzService.pauseQuartzCron(quartzEntity);
	}
	/**
	 * 停止任务
	 * @param quartzEntity
	 * @return
	 */
	@RequestMapping(value="/stopQuartzCron") 
	@ResponseBody
	public String stopQuartzCron(@RequestBody QuartzEntity quartzEntity){
		return quartzService.stopQuartzCron(quartzEntity);
	}
}
